﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
typedef int BTDataType;
// ⼆叉链
typedef struct BinaryTreeNode
{
	struct BinTreeNode* left; // 指向当前结点左孩⼦
	struct BinTreeNode* right; // 指向当前结点右孩⼦
	BTDataType val; // 当前结点值域
}BTNode;
BTNode* BuyBTNode(BTDataType x)
{
	BTNode* arr = (BTNode*)malloc(sizeof(BTNode));
	if (arr == NULL)
	{
		perror("malloc arr");
		return;
	}
	arr->left = arr->right = NULL;
	arr->val = x;
	return arr;
}
BTNode* CreateTree()
{
	BTNode* n1 = BuyBTNode(1);
	BTNode* n2 = BuyBTNode(2);
	BTNode* n3 = BuyBTNode(3);
	BTNode* n4 = BuyBTNode(4);
	BTNode* n5 = BuyBTNode(5);
	BTNode* n6 = BuyBTNode(6);
	BTNode* n7 = BuyBTNode(7);
	n1->left = n2;
	n1->right = n4;
	n2->left = n3;
	n4->left = n5;
	n4->right = n6;
    n5->left = n7;
	return n1;
}
//前序遍历
void PreOrder1(BTNode* root)
{
	if (root == NULL)
	{
		printf("N ");
		return;
	}
	printf("%d ", root->val);
	PreOrder1(root->left);
	PreOrder1(root->right);

}
//中序遍历
void PreOrder2(BTNode* root)
{
	if (root == NULL)
	{
		printf("N ");
		return;
	}
	PreOrder2(root->left);
	printf("%d ", root->val);
	PreOrder2(root->right);

}
//后序遍历
void PreOrder3(BTNode* root)
{
	if (root == NULL)
	{
		printf("N ");
		return;
	}
	PreOrder3(root->left);
	PreOrder3(root->right);
	printf("%d ", root->val);
}
//求根节点个数
int shu(BTNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	return shu(root->left) + shu(root->right) + 1;
}
//求叶子节点个数
int yeshu(BTNode* root)
{
	if (root == NULL)
		return 0;
	if (root->left == NULL && root->right == NULL)
	{
		return 1;
	}
	return yeshu(root->left) + yeshu(root->right);
}
//求高
int gao(BTNode* root)
{
	if (root == NULL)
		return 0;
	int zhu = gao(root->left);
	int you = gao(root->right);
	return zhu > you ? zhu + 1 : you + 1;
}
int main()
{
	BTNode* arr = CreateTree();
	//PreOrder2(arr);
	printf("%d", gao(arr));
	return 0;
}